package com.lamp.main;

import java.util.Arrays;
import java.util.LinkedList;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;

import com.lamp.downloadimage.BitmapCache;
import com.lamp.downloadimage.ImageDownloader;
import com.lamp.horizontal.PullToRefreshListView;
import com.lamp.horizontal.PullToRefreshListView.OnRefreshListener;

public class MineActivity extends Activity {
	private View footer;
	private String[] mStrings = {};
	private PullToRefreshListView listPull;
	private LinkedList<String> mListItems;
	private ImageDownloader imageDownloader;
	private int userId;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mine);
		footer = ((LayoutInflater) this
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
				R.layout.mine_content, null, false);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, mStrings);
		listPull = (PullToRefreshListView) findViewById(R.id.pulltorefresh);
		listPull.addFooterView(footer);
		listPull.setAdapter(adapter);
		listPull.setOnRefreshListener(new OnRefreshListener() {
			public void onRefresh() {
				Log.v("GetUser", "onRefresh");
				new GetDataTask().execute();
			}

			public void onRefreshNext() {

			}
		});
		
		this.imageDownloader = new ImageDownloader(new BitmapCache());
		mListItems = new LinkedList<String>();
		mListItems.addAll(Arrays.asList(mStrings));

		Bundle extras = getIntent().getExtras();
		this.userId = extras.getInt("userId");
		
	}
	private class GetDataTask extends AsyncTask<Void, Void, String[]> {

		@Override
		protected String[] doInBackground(Void... params) {
			// Simulates a background job.
			try {
				Thread.sleep(2000);

			} catch (InterruptedException e) {
				;
			}
			return mStrings;
		}

		@Override
		protected void onPostExecute(String[] result) {
			mListItems.addFirst("Added after refresh...");

			// Call onRefreshComplete when the list has been refreshed.
			PullToRefreshListView listPull = (PullToRefreshListView) findViewById(R.id.pulltorefresh);
			listPull.onRefreshComplete();
			super.onPostExecute(result);
		}
	}
}
